Answer:

Yes — since each can only be seen in the body of its method, each can be declared to be of any type.

Of course, the formal parameters of any one method must all have different names, regardless of their type.

One-way Glass

one way glass

 

It is sometimes useful to visualize methods as being surrounded by a box of "one-way glass." A method can see local variables and parameters that are inside the box. A method can look out through the glass that surrounds it. But no outsider can see into the box.

The picture shows the one-way glass for the example program. The red lines show the box of one-way glass surrounding each method. The method can see out of its box (for example each method can see the instance variable balance) but other methods can't see from the outside into the box of one-way glass.

In processDeposit() the statement can "see" the variable balance declared as a instance variable. It can also see the parameter amount that is inside its box.

The method showCharge() is defective because it contains a statement that attempts to look inside the box that surrounds processCheck().

The names of formal parameters (such as amount) and local variables (such as charge) are only visible from inside the glass box. However, the number and type of actual parameters required for each method is known by outsiders.

QUESTION 7:

Is the name of a method inside or outside the glass box?